<template>
  <div>
    <pages-header
      ref="pageHeader"
      :title="$route.params.id ? '队员列表' : '队员列表'"
      :backUrl="$routeProStr + '/task/list'"
      style="margin-bottom: 10px"
    ></pages-header>

    <el-card :bordered="false" shadow="never" class="ivu-mb-16" :body-style="{ padding: 0 }">
      <div class="padding-add">
        <el-form ref="params" :model="params" @submit.native.prevent inline>
          <el-form-item label="队员名称/编号/代号：" prop="status2" label-for="status2">
            <el-input clearable v-model="params.search" placeholder="请输入名称/编号/代号" class="form_content_width" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" v-db-click @click="getData">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button v-db-click @click="setTeamAudit">队员审核</el-button>
            <el-button v-db-click @click="setTeamDuties">设置职务</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card :bordered="false" shadow="never" class="ivu-mt">
      <!-- <el-row :gutter="24" justify="space-between" style="margin-bottom: 10px">
        <el-col :span="24">
          <el-button v-db-click @click="setTeamAudit">队员审核</el-button>
          <el-button v-db-click @click="setTeamDuties">设置职务</el-button>
        </el-col>
      </el-row> -->

      <el-table
        :border="false"
        class="vxeTable"
        highlight-hover-row
        highlight-current-row
        :loading="loading"
        ref="xTable"
        header-row-class-name="false"
        :data="tableData"
        @select="handleSelectRow"
        @select-all="handleSelectRow"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="ID" min-width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="队员名称" min-width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.username }}</span>
          </template>
        </el-table-column>
        <el-table-column label="队员头像" min-width="100">
          <template slot-scope="scope">
            <img :src="scope.row.avatar" width="50" />
          </template>
        </el-table-column>
        <el-table-column label="手机号" min-width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.phone }}</span>
          </template>
        </el-table-column>
        <el-table-column label="蓝天编号" min-width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.numbering }}</span>
          </template>
        </el-table-column>
        <el-table-column label="蓝天代号" min-width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.codename }}</span>
          </template>
        </el-table-column>
        <el-table-column label="职务" min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.identity == 1">队长</span>
            <span v-if="scope.row.identity == 2">指挥</span>
            <span v-if="scope.row.identity == 3">装备管理员</span>
            <span v-if="scope.row.identity == 4">现场信息员</span>
            <span v-if="scope.row.identity == 5">后台信息员</span>
          </template>
        </el-table-column>
        <el-table-column label="审核" min-width="80">
          <template slot-scope="scope">
            <span v-if="scope.row.audit == 0">审核中</span>
            <span v-if="scope.row.audit == 1">通过</span>
            <span v-if="scope.row.audit == 2">未通过</span>
          </template>
        </el-table-column>
        <el-table-column label="出发时间" min-width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.set_off_status == 0">未出发</span>
            <span v-if="scope.row.set_off_status == 1">{{ scope.row.set_off_time }}</span>
          </template>
        </el-table-column>
        <el-table-column label="签到时间" min-width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.sign_status == 0">未签到</span>
            <span v-if="scope.row.sign_status == 1">{{ scope.row.sign_time }}</span>
          </template>
        </el-table-column>
        <el-table-column label="签到照片" min-width="120">
          <template slot-scope="scope">
            <div v-if="scope.row.sign_image.length !== 0" v-viewer>
              <div class="tabBox_img">
                <img v-lazy="scope.row.sign_image" />
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="返回时间" min-width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.return_status == 0">未返回</span>
            <span v-if="scope.row.return_status == 1">{{ scope.row.return_time }}</span>
          </template>
        </el-table-column>
        <el-table-column label="到达时间" min-width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.arrive_status == 0">未到达</span>
            <span v-if="scope.row.arrive_status == 1">{{ scope.row.arrive_time }}</span>
          </template>
        </el-table-column>
      </el-table>

      <div class="acea-row row-right page">
        <pagination
          v-if="total"
          :total="total"
          :page.sync="params.page"
          :limit.sync="params.limit"
          @pagination="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { getTeamList, setAudit, setDuties } from '@/api/task';

export default {
  name: 'teamList',
  data() {
    return {
      total: 0,
      params: {
        search: '',
        page: 1,
        limit: 15,
      },
      loading: false,
      tableData: [],
      selectedIds: [],
    };
  },
  components: {},
  computed: {},
  mounted() {
    if (this.$route.params.id) {
      this.getData();
    }
  },
  methods: {
    handleSelectRow(selection) {
      let ids = [];
      selection.map((e) => {
        ids.push(e.id);
      });
      this.selectedIds = ids;
    },
    pageChange() {
      this.getData();
    },
    // 列表
    getData() {
      this.loading = true;
      this.params.id = this.$route.params.id;
      getTeamList(this.params)
        .then(async (res) => {
          this.tableData = res.data.list;
          this.total = res.data.count;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$message.error(res.msg);
        });
    },
    setTeamAudit() {
      if (this.selectedIds.length === 0) {
        this.$message.warning('请选择队员');
      } else {
        let data = { ids: this.selectedIds, task_id: this.$route.params.id };
        this.$modalForm(setAudit(data)).then(() => {
          this.selectedIds = [];
          this.getData();
        });
      }
    },
    setTeamDuties() {
      if (this.selectedIds.length === 0) {
        this.$message.warning('请选择队员');
      } else {
        let data = { ids: this.selectedIds, task_id: this.$route.params.id };
        this.$modalForm(setDuties(data)).then(() => {
          this.selectedIds = [];
          this.getData();
        });
      }
    },
  },
};
</script>

<style scoped lang="scss">
.vxeTable {
  > .vxe-table--header-wrapper {
    background: #fff !important;
  }

  .icon {
    font-size: 20px;
  }
}
::v-deep .vxe-table--render-default .vxe-table--border-line {
  z-index: 2 !important;
}
.rule {
  display: flex;
  flex-wrap: wrap;
  overflow-y: scroll;
  height: max-content;
  max-height: 600px;
  flex: 1;
}
.tree::-webkit-scrollbar {
  width: 2px;
  background-color: #f5f5f5;
}
/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
.rule::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  background-color: #f5f5f5;
}

/*定义滚动条轨道 内阴影+圆角*/
.rule::-webkit-scrollbar-track {
  border-radius: 4px;
  background-color: #f5f5f5;
}

/*定义滑块 内阴影+圆角*/
.rule::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background-color: #ccc;
}

.rule-list {
  background-color: #f2f2f2;
  width: 48.5%;
  height: max-content;
  margin: 5px;
  border-radius: 3px;
  padding: 10px;
  color: #333;
  cursor: pointer;
  transition: all 0.1s;
}

.rule-list:hover {
  background-color: #badbfb;
}

.rule-list div {
  white-space: nowrap;
}

.select-rule {
  background-color: #badbfb;
}
.route-list {
  display: flex;
  margin-top: 10px;

  .tree {
    width: 200px;
    overflow-y: scroll;
    max-height: 600px;
    ::v-deep .el-tree-node__children .el-tree-node .el-tree-node__content {
      padding-left: 14px !important;
    }
  }
}
.delAll {
  margin-bottom: 10px;
}
</style>
